import { Response } from '@/types/Common';
import { AdminUserLoginResponse } from '@/types/AdminUser';
import axios from '../request';

export default {
  /**
   * @param {string} username
   * @param {string} password
   * @return {Promise<Response<AdminUserLoginResponse>>}
   */
  login: async (username, password) => {
    const res = await axios.post(
      `/Api/AdminUsers/login?u_account=${username}&u_password=${password}`
    );
    return res.data;
  },
  /**
   *
   * @param {AdminUserInfo} body
   * @return {Promise<Response<PageResponse<AdminUserInfo>>>}
   */
  page: async (body) => {
    const res = await axios.post(
      `/Api/AdminUsers/getList?page=${body.page}&pageSize=${body.pageSize}`,
      body
    );
    return res.data;
  },
  /**
   *
   * @param {AdminUserInfo} body
   * @return {Promise<Response<AdminUserInfo>>}
   */
  add: async (body) => {
    const res = await axios.post('/Api/AdminUsers/add', body);
    return res.data;
  },
  delete: async (id) => {
    const res = await axios.post('/Api/AdminUsers/delete', { u_id: id });
    return res.data;
  },
  /**
   *
   * @param {AdminUserChangePasswordRequest} body
   * @return {Promise<any>}
   */
  changePassword: async (body) => {
    const res = await axios.post('/Api/AdminUsers/changePassword', body);
    return res.data;
  },
  resetPassword: async (uid) =>{
    const res = await axios.post('Api/AdminUsers/reset_pswd', {u_id: uid});
    return res.data;
  },
  getRoles: async () => {
    const res = await axios.post('/Api/AdminUsers/getroles');
    return res.data;
  },
  updateLevel: async (userId, levelId) => {
    const res = await axios.post('/Api/AdminUsers/update', {
      u_id: userId,
      u_level: levelId,
    });
    return res.data;
  },
};
